<?php

namespace App\Http\Controllers\Mobile;


use App\Logics\EventLogic;
use App\Logics\OrderLogic;

class EventController extends BaseController
{
    // 赛事，研学，沙龙等
    // 一般操作
    public function initialize()
    {
        parent::initialize();
    }

    // 列表
    public function lists()
    {
        // 指定审核通过后的活动
        $option = $this->optLogic();
        $option->setField('verify', 1);
        $option->setField('is_sale', 1);

        // 查询
        $logic  = new EventLogic();
        $result = $logic->getLists($this->myUid);
        if($result === false){
            return $this->error($logic->getError());
        }

        return $this->success($result);
    }

    // 详情
    public function show()
    {
        $logic = new EventLogic();
        $info  = $logic->onShow($this->myUid);
        if($info === false){
            return $this->error($logic->getError());
        }
        if(empty($info)){
            return $this->error('内容不存在！');
        }

        // 最新报名用户  $info['student']
        $students = (new OrderLogic())->getStudent();
        $stuCount = count($students);
        if($stuCount < 7){
            for($ii = 0; $ii < 7 - $stuCount; $ii++){
                $students[] = [
                    'uid'         => 0,
                    'student_id'  => 0,
                    'order_uid'   => 0,
                    'person_name' => '',
                    'head_img'    => 'https://img.hiyiku.com/temp/face_'.($ii + 1).'.jpg',
                    'sex'         => 0,
                    'age'         => 0,
                    'guardor'     => '',
                    'mobile'      => '',
                ];
            }
        }
        // 整理 报名学员
        $info['student'] = $students;

        return $this->success($info);
    }

    #####################################################################################################
    ## 已经转移 待删除

    // 我发布的
    public function _my()
    {
        if(empty($this->myUid)){
            return $this->error('请先登录！', [], LOGIN_ERROR);
        }

        // 指定用户
        $option = $this->optLogic();
        $option->setField('uid', $this->myUid);

        // 查询
        $logic  = new EventLogic();
        $result = $logic->getLists();
        if($result === false){
            return $this->error($logic->getError());
        }

        return $this->success($result);
    }

    // 我参加的
    public function _join()
    {
        if(empty($this->myUid)){
            return $this->error('请先登录！', [], LOGIN_ERROR);
        }

        // 指定用户
        $option = $this->optLogic();
        $option->setField('order_uid', $this->myUid);
        $option->setField('add_event', 1);

        // 查询
        $logic  = new OrderLogic();
        $result = $logic->getStudent();
        if($result === false){
            return $this->error($logic->getError());
        }

        return $this->success($result);
    }

    // 发布活动
    public function _publish()
    {
        $user = $this->myUser;
        if(empty($user)){
            return $this->error('请先登录！', [], LOGIN_ERROR);
        }
        if(empty($user['is_auth'])){
            return $this->error('你不是认证用户！');
        }
        if($user['verify'] != 1){
            return $this->error('你选择的用户认证未通过！');
        }

        // 查询
        $logic  = new EventLogic();
        $result = $logic->onAdd($this->myUid);
        if($result === false){
            return $this->error($logic->getError());
        }

        return $this->success($result);
    }

}


